package com.weibo.host.severlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.weibo.common.BaseSeverlet;
import com.weibo.common.CommonUtil;
import com.weibo.host.service.HostService;
import com.weibo.host.service.imp.HostServiceImp;

public class SelectHostSeverlet extends BaseSeverlet {
	private static Logger logger = Logger.getLogger(SelectHostSeverlet.class);

	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			HostService hostService = new HostServiceImp();
			String currentPage = request.getParameter("currentPage");
			if (currentPage == null || "".equals(currentPage)) {
				currentPage = "1";
			}

			// 获取微博主列表
			List list = hostService.getHostList_ForVisitor(Integer
					.parseInt(currentPage) - 1);
			request.setAttribute("hostList", list);

			// 获取微博主列表的总条目数
			int TotalPageNum = CommonUtil.getTotalPageNum(hostService
					.getHostTotalSize());
			request.setAttribute("currentPage", currentPage);
			request.setAttribute("totalPageNum", TotalPageNum);

			request.getRequestDispatcher("/WEB-INF/task/select_weibo_host.jsp").forward(
					request, response);
		} catch (ServletException e) {
			e.printStackTrace();
			logger.error(e);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error(e);
		}

	}

}
